'Where ObjectType and CombinationMethod are single bytes and all the other are double
'bytes (integers). ObjectType and CombinationMethod values are defined in the Enum
'structures below for ObjectTypes and Methods. If any property is not used it
'is 0, and still takes up the same 2 bytes, so each record is of the same length.
'
'In the case of a polygon object type the fixed length object bytes are followed by
'an integer which specifies the length (in integers, so double this number of bytes)
'of a variable length section containing integer points in the polygon, X followed by Y.
'For polygons the Top property specifies Winding or Alternate fill.
Option Explicit
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Const RGN_AND = 1
Private Const RGN_COPY = 5
Private Const RGN_DIFF = 4
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Public Enum ObjectTypes
Rectangle = 0
Polygon = 1
RoundedRectangle = 2
Ellipse = 3
End Enum
Public Enum Methods
ANDCombine = 0
ORCombine = 1
XORCombine = 2
NOTCombine = 3
End Enum
Public Function ReadFormRegion(FileName As String) As Long
Dim Buffer As String, ByteBuffer As Byte, IntegerBuffer As Integer
Dim ObjectType As ObjectTypes, Top As Integer, Left As Integer, Right As Integer, Bottom As Integer, RoundedRectX As Integer, RoundedRectY As Integer, Method As Methods
Dim DObjectRegion As Long, ResultRegion As Long, HolderRegion As Long
Dim First As Boolean, Counter As Integer, PolyCount As Integer, PolyPoints() As POINTAPI
'Open the file
Open FileName For Binary As #1
Buffer = "*****" 'Read 5 bytes
Get #1, , Buffer
'Check for validity
If Buffer <> "VBSFC" Then
MsgBox FileName + " is not a valid data file.", vbOKOnly Or vbCritical, "VB Shaped Form Creator"
Close #1
Exit Function
End If
'Create Polygon Points buffer
Seek #1, 8
Get #1, , IntegerBuffer
ReDim PolyPoints(0 To IntegerBuffer - 1) As POINTAPI
ResultRegion = CreateRectRgn(0, 0, 0, 0)
HolderRegion = CreateRectRgn(0, 0, 0, 0)
First = True
Do
Get #1, , ByteBuffer: ObjectType = ByteBuffer
Get #1, , IntegerBuffer: Top = IntegerBuffer
Get #1, , IntegerBuffer: Left = IntegerBuffer
Get #1, , IntegerBuffer: Right = IntegerBuffer
Get #1, , IntegerBuffer: Bottom = IntegerBuffer
Get #1, , IntegerBuffer: RoundedRectX = IntegerBuffer
Get #1, , IntegerBuffer: RoundedRectY = IntegerBuffer